#include "StdAfx.h"
#include "Food.h"
#include "SnakeSView.h";
#include "Body.h"
#include "Snake.h"

Food::Food(CSnakeSView* pView1)
{
	int t=1;
	int x1=0;
	int y1=0;
	while(t==1)
	{
		x1=rand()%20;
		y1=rand()%30;

		Body* body=pView1->getSnake()->getHead();
		t=0;
		while(body!=NULL)
		{
			if(body->x==x1&&body->y==y1)
			{   
				t=1;
				break;
			}
			else body=body->pre;
		}
	}
	x=x1;
	y=y1;
}


Food::~Food(void)
{
}


void Food::DrawFood(CDC* pDC)
{

	if(x==-1&&y==-1) return ;
	CBrush br;
	br.CreateSolidBrush(RGB(255,0,0));
	pDC->SelectObject(&br);
	pDC->Rectangle(10*x+12,10*y+12,10*x+20,10*y+20);
	br.DeleteObject();
}
